﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _4_7
{
    public partial class Form1 : Form
    {
        private void Form1_DoubleClick(object sender, EventArgs e)
        {
            timer1.Enabled = true;
        }
        private void LoadBackGround()
        {
            Bitmap backPic = new Bitmap("发射场.jpg");
            this.BackgroundImage = backPic;
            this.ClientSize = new Size(backPic.Width, backPic.Height);
        }
        // 初始化火箭
        private void InitRocket()
        {
            Bitmap pic = new Bitmap("火箭.gif");
            pictureBox1.Image = pic;
            pictureBox1.BackColor = Color.Transparent;
            pictureBox1.Size = new Size(pic.Width, pic.Height);
            // 水平居中，底部隐藏喷射效果
            pictureBox1.Left = this.ClientSize.Width / 2 - pictureBox1.Width / 2;
            pictureBox1.Top = this.ClientSize.Height - pictureBox1.Height + 100;
        }
        // 初始化进度条
        private void InitProgress()
        {
            progressBar1.Dock = DockStyle.Top;
            progressBar1.Maximum = pictureBox1.Top + pictureBox1.Height;
            progressBar1.Minimum = 0;
            progressBar1.Value = 0;
        }

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            LoadBackGround();
            InitRocket();
            InitProgress();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            pictureBox1.Top--; // 火箭上升
            progressBar1.Value++; // 进度更新
                                  // 火箭飞出窗体，停止动画
            if (progressBar1.Value >= progressBar1.Maximum)
            {
                timer1.Enabled = false;
                MessageBox.Show("火箭发射成功！");
            }
        }
    }
}
